import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import { registerMicroApps, start } from "qiankun";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

let app = createApp(App);
app.use(ElementPlus);

// 初始化全局状态
const initialState = {
  token: localStorage.getItem("token") || "",
};

// 注册子应用
registerMicroApps(
  [
    {
      name: "firstApp", // app name registered
      entry: "//localhost:5173",
      container: "#subapp-container",
      activeRule: "/firstApp",
      props: {
        // 传递给子应用的props
        getToken: () => localStorage.getItem("token") || "",
      },
    },
    {
      name: "secondApp",
      entry: "//localhost:5174",
      container: "#subapp-container",
      activeRule: "/secondApp",
      props: {
        // 传递给子应用的props
        getToken: () => localStorage.getItem("token") || "",
      },
    },
  ]
);

start({
  sandbox: {
    experimentalStyleIsolation: true, // 开启样式隔离
  },
});

app.mount("#app");
